#include "Callable.h"

Callable::Callable(Module *M, const Type *RetType) : M(M), RetType(RetType) {}

Callable& Callable::AddType(const Type* Ty) {
	ArgTys.push_back(Ty);
	return *this;
}

void Callable::Map(void *Ptr, ExecutionEngine *EE, const char * Name) {
	FunctionType *FuncTy = FunctionType::get(RetType, ArgTys, false);
	Func = Function::Create(FuncTy, GlobalValue::ExternalLinkage, Name, M);
	EE->addGlobalMapping(Func, Ptr);
}

CallInst* Callable::Call(Value *Params[], Instruction *InsertAfter) {
	return CallInst::Create(Func, Params, Params + ArgTys.size(), "", InsertAfter);
}
